package com.sv.utils.ibatis;

import java.lang.reflect.Field;

import org.springframework.util.ReflectionUtils;

import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;

public class SqlMapClientFactoryBean extends
        org.springframework.orm.ibatis.SqlMapClientFactoryBean {

    private com.ibatis.sqlmap.engine.execution.SqlExecutor sqlExecutor = new SqlExecutor();

    @Override
    public void afterPropertiesSet() throws Exception {
        super.afterPropertiesSet();
        if (null != getSqlExecutor()) {
            SqlMapClientImpl sqlMapClient = (SqlMapClientImpl) getObject();
            Field field = ReflectionUtils.findField(sqlMapClient.getDelegate().getClass(),
                    "sqlExecutor");
            field.setAccessible(true);
            field.set(sqlMapClient.getDelegate(), getSqlExecutor());
        }

    }

    public com.ibatis.sqlmap.engine.execution.SqlExecutor getSqlExecutor() {
        return sqlExecutor;
    }

    public void setSqlExecutor(
            com.ibatis.sqlmap.engine.execution.SqlExecutor sqlExecutor) {
        this.sqlExecutor = sqlExecutor;
    }

}
